package cn.tedu.coolshark.Controller;

import cn.tedu.coolshark.mapper.CategoryMapper;
import cn.tedu.coolshark.pojo.entity.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryMapper mapper;

    //处理首页分类展示的请求
    @RequestMapping("/select")
    public List<Category> select() {
        return mapper.select();
    }

    //处理删除分类的请求
    @RequestMapping("/delete")
    public void delete(int id) {
        mapper.deleteById(id);
    }

    //处理添加分类的请求
    @RequestMapping("/insert")
    public void insert(String name) {
        mapper.insert(name);
    }

    //处理修改分类的请求
    @RequestMapping("/update")
    public void update(@RequestBody Category category) {
        mapper.update(category);
    }
}
